/*
 * @Author: WangLi
 * @Date: 2021-08-26 12:30:04
 * @LastEditors: WangLi
 * @LastEditTime: 2024-05-07 14:58:37
 */
import createRouter from "@shene/wx-router";
import { sleep } from "../utils/util";
import { getUser } from "../utils/storage";

const WHITE_PAGES = ["/pages/welcome/index"];

const router = createRouter({
  whites: WHITE_PAGES,
});

const isLogin = () => {
  const userInfo = getUser();
  return userInfo && userInfo.token;
};

const getPath = (path) => {
  const url = path.split("?")[0];
  return url.startsWith("/") ? url : "/" + url;
};

router.beforeEach((to, next) => {
  // if (isLogin() || WHITE_PAGES.includes(getPath(to.path))) {
  //   next(to);
  // } else {
  //   next(LOGIN_PAGE);
  // }
  next(to);
});

router.beforeLoad(async (currentPath, next) => {
  // if (isLogin() || WHITE_PAGES.includes(getPath(currentPath))) {
  //   return true;
  // }
  return true;
  await sleep(300);
  // next(LOGIN_PAGE);
  return false;
});

export default router;
